package com.training.mapper;

import com.training.entity.PurchaseRecord;
import com.training.entity.Course; // To retrieve course details in purchase history
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Options;

import java.util.List;

@Mapper
public interface PurchaseRecordMapper {

    /**
     * Find all non-logically deleted purchase records for a student.
     * Joins with the course table to get course details.
     * @param studentId Student ID
     * @return List of Course objects that the student has purchased
     */
    List<Course> findPurchasedCoursesByStudentId(@Param("studentId") Long studentId);

    /**
     * Insert a new purchase record.
     * @param purchaseRecord PurchaseRecord object to insert
     * @return Number of affected rows
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertPurchaseRecord(PurchaseRecord purchaseRecord);

    /**
     * Check if a student has already purchased a specific course.
     * @param studentId Student ID
     * @param courseId Course ID
     * @return Count of records, >0 means already purchased
     */
    int countPurchaseRecord(@Param("studentId") Long studentId, @Param("courseId") Long courseId);

    /**
     * 统计学生在某个课程的报名记录数量。
     * @param studentId 学生ID
     * @param courseId 课程ID
     * @return 报名记录数量，如果为 0 则表示未报名。
     */
    Integer countByStudentIdAndCourseId(@Param("studentId") Long studentId, @Param("courseId") Long courseId);

    /**
     * 插入一条购买/报名记录。
     * @param purchaseRecord 购买记录实体。
     * @return 影响的行数。
     */
    // int insertPurchaseRecord(PurchaseRecord purchaseRecord); // 如果有 PurchaseRecord 实体和相应的表

    // ... 其他与购买记录相关的方法
}
